<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript image dropdown - Object oriented approach</title>
<link rel="stylesheet" href="css/sample.css" />
<script src="../js/jquery/jquery-1.9.0.min.js"></script>
<script src="../js/jquery/tester.js"></script>
<!-- <msdropdown> -->
<link rel="stylesheet" type="text/css" href="../css/msdropdown/dd.css" />
<script src="../js/msdropdown/jquery.dd.min.js"></script>
<!-- </msdropdown> -->
</head>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="5" class="topmenu">
  <tr>
    <td colspan="2" class="top"><h1>Javascript image dropdown <span id="ver"></span> <a title="Download" href="http://www.marghoobsuleman.com/jquery-image-dropdown" class="small">Download</a></h1></td>
  </tr>
  <tr>
    <td width="25%"><select style="width:250px"  name="pages" id="pages">
      <option value="" selected="selected">Choose a sample page</option>
      <option value="index.html">Normal</option>
      <option value="byjson.html">By Json Data</option>
      <option value="multiple-skin.html">Multiple Skin</option>
      <option value="css-sprite.html">CSS Sprite</option>
      <option value="object-oriented-approach.html">Object Oriented Approach</option>
      <option value="object-oriented-approach-more.html">Object Oriented Approach - More</option>
      <option value="use-checkbox.html">Use Checkbox</option>
      <option value="mouse-events.html">Mouse Events</option>
      <option value="help.html">Documentation</option>
    </select></td>
    <td align="left"><a href="help.html">Documentation</a></td>
  </tr>
</table>
<form action="submitdata.php" method="post" enctype="multipart/form-data" name="frmdata">
<table width="100%" border="0" cellspacing="1" cellpadding="5" class="tblWhite">
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" valign="top">Object Oriented Approch</td>
  </tr>
  <tr>
    <td width="24%" valign="top">
    <select style="width:200px"  name="browsers" id="browsers">
      <option value="chrome" data-image="../images/msdropdown/icons/browser-chrome.png">Chrome</option>
      <option value="safari" data-image="../images/msdropdown/icons/browser-safari.png">Safari</option>
      <option value="firefox" data-image="../images/msdropdown/icons/browser-firefox.png">Firefox</option>
      <option value="opera"  data-image="../images/msdropdown/icons/browser-opera.png">Opera</option>
      <option value="ie9" data-image="../images/msdropdown/icons/browser-msie.png">IE 9</option>
      <option value="ie8" data-image="../images/msdropdown/icons/browser-msie.png">IE 8</option>
      <option value="ie7" data-image="../images/msdropdown/icons/browser-msie.png">IE 7</option>
      <option value="ie6" data-image="../images/msdropdown/icons/browser-msie.png">IE 6</option>
    </select>
    </td>
    <td width="21%" valign="top">&nbsp;</td>
    <td width="55%" valign="top"><div id="debugger">
      <ul class="debug" id="testResults">
        
      </ul>
    </div></td>
  </tr>
  <tr>
    <td colspan="2" valign="top"><pre>//create
<code>var oHandler1 = $(&quot;#browsers&quot;).msDropdown().data(&quot;dd&quot;);</code>
</pre></td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><input type="button" name="getIndex" id="getIndex" value="Get selectedIndex" /></td>
    <td valign="top" class="viewcode">view code</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr class="hidden">
    <td colspan="2" valign="top"><pre>
<code>$("#getIndex").on("click", function() {
    //var index = oHandler1.get("selectedIndex"); 
    var index = oHandler1.selectedIndex; //above line is same
    console.log("index: "+index);
});</code></pre></td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><input name="txt_index" type="text" id="txt_index" value="2" size="10" />
      <input type="button" name="setIndex" id="setIndex" value="Set selectedIndex" /></td>
    <td valign="top" class="viewcode">view code</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr class="hidden">
    <td colspan="2" valign="top"><pre>
<code>$("#setIndex").on("click", function() {
    var ind = document.getElementById("txt_index").value;
    oHandler1.set("selectedIndex", ind);
});</code></pre></td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><input type="button" name="btnDisable" id="btnDisable" value="Toggle Disable" /></td>
    <td valign="top" class="viewcode">view code</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr class="hidden">
    <td colspan="2" valign="top"><pre>
<code>$("#btnDisable").on("click", function() {
    var isDisabled = oHandler1.get("disabled");
    oHandler1.set("disabled", !isDisabled);	
});</code></pre></td>
<td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><input type="button" name="btnOpen" id="btnOpen" value="Hover to open/close" /></td>
    <td valign="top" class="viewcode">view code</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr class="hidden">
    <td colspan="2" valign="top"><pre>
<code>$("#btnOpen").on("mouseenter", function() {
    oHandler1.open();
});</code></pre></td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><input type="button" name="btnShowHide" id="btnShowHide" value="Toggle Show" /></td>
    <td valign="top" class="viewcode">view code</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr class="hidden">
    <td colspan="2" valign="top"><pre>
<code>$("#btnShowHide").on("click", function() {
    var isVisible = oHandler1.visible();
    oHandler1.visible(!isVisible);
});</code></pre></td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><input type="button" name="getUIData" id="getUIData" value="Get uiData" /></td>
    <td valign="top" class="viewcode">view code</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr class="hidden">
    <td colspan="2" valign="top"><pre>
<code>$("#getUIData").on("click", function() {
    var uiData = oHandler1.uiData;
    console.log(uiData)'
});</code></pre></td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td valign="top">&nbsp;</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" valign="bottom"><input type="submit" value="Submit" /></td>
  </tr>
  <tr>
    <td colspan="3" valign="bottom">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" valign="top">&nbsp;</td>
  </tr>
</table>
</form>
<p>&nbsp;</p>

<script>
/************** for testing purpose ************************/
function Element(nm, attr, html) {
		var tag = document.createElement(nm);
		if (attr) {
		 for(var i in attr) {
			 switch(i) {
				 case "style":
					tag.style.cssText  = attr[i];
				 break;
				 default:
					tag[i]  = attr[i];
				 break;
			 };	
		 };
		};
		if (html) {
		 tag.innerHTML = html;
		};
		return tag;
	};
/************** for testing purpose ************************/	

var oHandler1;// this will be assign in onready below
$(document).ready(function(e) {	
	oHandler1 = $("#browsers").msDropdown({
			on:{create:function() {
				//console.log("Created");
				test("Test msDropdown", function(){assert(true, "msdropdown is created for 'select#browsers'...");});				
			},
			change: function(data, ui) {
				assert(true, "value: "+data.value + ", label: "+data.text)
			}
			}
			}).data("dd");


	//assign action on buttons
	$("#getIndex").on("click", function() {
		//var index = oHandler1.get("selectedIndex"); 
		var index = oHandler1.selectedIndex; //above is same
		assert(true, "current index is "+index);
//		console.log("index: "+index);
	});
	$("#setIndex").on("click", function() {
		var ind = document.getElementById("txt_index").value;
		oHandler1.set("selectedIndex", ind);
		assert(true, "selectedIndex has been changed to "+ind);
	});
	$("#btnDisable").on("click", function() {
		var isDisabled = oHandler1.get("disabled");
		oHandler1.set("disabled", !isDisabled);	
		assert(true, "disabled = "+!isDisabled);
	});
	$("#btnOpen").on("mouseenter", function() {
		oHandler1.open();
	});
	
	$("#btnShowHide").on("click", function() {
		var isVisible = oHandler1.visible();
		oHandler1.visible(!isVisible);
	});
	
	$("#getUIData").on("click", function() {
		var uiData = oHandler1.uiData;
		var val = "data";
		test("uiData."+val, function() {
					for(var j in uiData[val]) {
						assert(true, j +" : <span class='black'>"+uiData[val][j]+"</span>");
					}
		});
		val = "option";
		test("uiData."+val, function() {
			assert(true, "value : <span class='black'>"+uiData[val].value+"</span>");
			assert(true, "text : <span class='black'>"+uiData[val].text+"</span>");
		});		
		test("", function() {
			assert(true, "uiData.index: "+uiData.index);
		});
		val = "ui";
		test("uiData."+val, function() {
			assert(true, uiData[val][0].outerHTML);
		});
		
		//console.log(uiData)
	});
	
	
	$(".viewcode").on("click", function(e) {		
		$(this).parent().next().toggle("show");
	})
	var html = "<div class='app'>This is last div</div>";
	//no use
	try {
		var pages = $("#pages").msDropdown({on:{change:function(data, ui) {
												var val = data.value;
												if(val!="")
													window.location = val;
											}}}).data("dd");

		var pagename = document.location.pathname.toString();
		pagename = pagename.split("/");
		pages.setIndexByValue(pagename[pagename.length-1]);
		$("#ver").html(msBeautify.version.msDropdown);
	} catch(e) {
		//console.log(e);	
	}
	
	$("#ver").html(msBeautify.version.msDropdown);
});

</script>

</body>
</html>
